package priv.bruce.servlet;

import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.alibaba.fastjson.JSON;

import priv.bruce.entry.UserInfo;
import priv.bruce.service.UserService;


public class Display extends HttpServlet {
	private static final long serialVersionUID = 1L;
	private UserService userInfo = new UserService();
	UserInfo user;

	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		response.setContentType("application/json;charset=utf-8");
		UserInfo user = (UserInfo) request.getSession().getAttribute("user");
		if(user==null) {
			response.getWriter().append(JSON.toJSONString(new ReturnResult(2, "no login", null)));
			return;
		}
		String username=user.getUser_name();
		
		try {
			user = userInfo.validUserInfo(username);
			if(user==null) {
				response.getWriter().append(JSON.toJSONString(new ReturnResult(2, "user is not exsist", null)));
				return;
			}
			response.getWriter().append(JSON.toJSONString(new ReturnResult(1, "success", user)));
		} catch (Exception e1) {
			e1.printStackTrace();
		}
		
	}

	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		doGet(request, response);
	}

}
